package com.eop.managedBean;

import java.util.List;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.DataModel;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.grid.impl.UIDataGrid;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.eop.entity.Minutes;
import com.eop.service.IMinutesService;

@ManagedBean(name = "eop_listMinutesBean", scope = ManagedBeanScope.REQUEST)
public class ListMinutesBean {
	private IMinutesService minutersServce = SpringBeanHolder
			.getBean("minutesService");
	@Inject
	private FacesContext context;
	@Accessible
	@SaveState
	private String eventId = FacesContext.getCurrentInstance()
			.getExternalContext().getRequestParameterMap().get("eventId");
	@Bind(id = "minutesGrid", attribute = "binding")
	private UIDataGrid minutesGrid_binding;

	@DataModel(id = "minutesGrid")
	private List<Minutes> getMinutesGrid() {
		return minutersServce.getMinutesByEvent(eventId);
	}

	@Action(id = "deleteMinute")
	public void deleteMinute() {
		Object[] obj = minutesGrid_binding.getSelectedValues();
		if (obj == null || obj.length == 0) {
			Browser.execClientScript("window.alert('请选择一条记录 ！');");
			return;
		}
		Minutes m = (Minutes) obj[0];
		m.setMinutes_DelFlag(true);
		minutersServce.saveMinutes(m);
		minutesGrid_binding.reload();
	}
}
